package com.uchedao.seller.http;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.uchedao.seller.SellerApplication;

/**
 * 网络请求管理器－－单例
 * Created by Administrator on 2015/6/2.
 */
public class VolleyUtil {
    /**
     * 单例
     */
    private static VolleyUtil mInstance;
    /**
     * 网络请求管理
     */
    private RequestQueue mRequestQueue;

    private VolleyUtil() {
        mRequestQueue = getRequestQueue();
    }

    /**
     * 获取单例
     */
    public static synchronized VolleyUtil getInstance() {
        if (mInstance == null) {
            mInstance = new VolleyUtil();
        }
        return mInstance;
    }

    public RequestQueue getRequestQueue() {
        if (mRequestQueue == null) {
            // getApplicationContext() is key, it keeps you from leaking the
            // Activity or BroadcastReceiver if someone passes one in.
            mRequestQueue = Volley.newRequestQueue(SellerApplication.getAppContext());
        }
        return mRequestQueue;
    }

    public <T> void addToRequestQueue(Request<T> req) {
        getRequestQueue().add(req);
    }

}
